#!/bin/bash
## Adjust log dir if necessary
export LOG_DIR=/opt/logs/100000002/epcc-209
if [ ! -d "$LOG_DIR" ]; then
  mkdir -p $LOG_DIR
fi

## Adjust memory settings if necessary
export JAVA_OPTS="-server -Xms1024m -Xmx1024m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=384m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:SurvivorRatio=18"

export JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC -XX:ParallelGCThreads=4 -XX:MaxTenuringThreshold=9 -XX:+UseConcMarkSweepGC -XX:+DisableExplicitGC -XX:+UseCMSInitiatingOccupancyOnly -XX:+ScavengeBeforeFullGC -XX:+UseCMSCompactAtFullCollection -XX:+CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=9 -XX:CMSInitiatingOccupancyFraction=60 -XX:+CMSClassUnloadingEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:-ReduceInitialCardMarks -XX:+CMSPermGenSweepingEnabled -XX:CMSInitiatingPermOccupancyFraction=70 -XX:+ExplicitGCInvokesConcurrent -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationConcurrentTime -XX:+PrintHeapAtGC -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Duser.timezone=Asia/Shanghai -Dclient.encoding.override=UTF-8 -Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/./urandom"
export JAVA_OPTS="$JAVA_OPTS -Xloggc:$LOG_DIR/heap_trace.txt -XX:HeapDumpPath=$LOG_DIR/HeapDumpOnOutOfMemoryError/"
#apollo config env
export ENV=fat 
# 脚本所在的上层目录
cd `dirname $0`/..
# 项目代码路径
export CODE_HOME=`pwd`
# 设置依赖路径
export CLASSPATH="$CODE_HOME/classes:$CODE_HOME/lib/*"


if [[ -z "$JAVA_HOME" && -d /usr/java/latest/ ]]; then
    export JAVA_HOME=/usr/java/latest
fi
# java可执行文件位置
export _EXECJAVA="$JAVA_HOME/bin/java"
# 启动类
export MAIN_CLASS=com.ylink.epcc.Epcc209Application

printf "$(date) ==== Starting ==== \n"
$_EXECJAVA $JAVA_OPTS -classpath $CLASSPATH $MAIN_CLASS > $LOG_DIR/console.log 2>&1 & 
printf "Sleeping 5s to wait startting up\n"
sleep 5s
printf "\n-------------------------------------------\n"
printf "exec command [tail -fn30 $LOG_DIR/console.log] to view app console log\n"
printf "exec command [tail -f $LOG_DIR/epcc-209.log] to view app startup log\n"
printf "\n-------------------------------------------\n"
